package com.huatai.exchange.bootup.controller;

import com.faneui.bootup.controller.AbstractRestController;
import com.faneui.common.utils.BeanMapper;
import com.faneui.common.utils.ListUtils;
import com.huatai.exchange.dal.dao.ExcCommunicationDAO;
import com.huatai.exchange.dal.model.ExcCommunication;
import com.huatai.exchange.facade.ExcCommunicationController;
import com.huatai.exchange.facade.bean.CommunicationVo;
import com.huatai.exchange.facade.bean.CommunicationVo;
import com.huatai.exchange.facade.bean.QueryCommunicationVoListResp;
import com.huatai.exchange.facade.bean.QueryCommunicationVoListResp;
import com.huatai.exchange.service.ExcCommunicationService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "communication")
@Api("文件交换交互配置信息")
public class ExcCommunicationControllerImpl extends AbstractRestController implements ExcCommunicationController {

    @Autowired
    private ExcCommunicationService excCommunicationService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public QueryCommunicationVoListResp queryCommunicationVoList(@ModelAttribute CommunicationVo communicationVo) throws Exception {
        QueryCommunicationVoListResp resp = new QueryCommunicationVoListResp();
        try {
            ExcCommunication info = BeanMapper.map(communicationVo,ExcCommunication.class) ;
            List<ExcCommunication> infos = excCommunicationService.queryExcCommunicationList(info) ;
            if(ListUtils.isNotEmpty(infos)) {
                List<CommunicationVo> vos = BeanMapper.mapList(infos,CommunicationVo.class) ;
                resp.setCommunicationVos(vos);
            }
        }catch (Exception ex) {
            resp.setSuccess(false);
            resp.setMsg(ex.getMessage());
        }
        return resp;
    }
}
